# Maintainer: Joel Holdsworth <jholdsworth@nvidia.com>

_realname=bottle
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.13.3
pkgrel=1
pkgdesc="A fast and simple python micro-framework for small web-applications (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: python-bottle'
  'purl: pkg:pypi/bottle'
  "cpe: cpe:/a:bottlepy:bottle"
)
msys2_repository_url='https://github.com/bottlepy/bottle'
msys2_changelog_url='https://bottlepy.org/docs/dev/changelog.html'
msys2_documentation_url='https://bottlepy.org/docs/dev/index.html'
msys2_issue_tracker_url='https://github.com/bottlepy/bottle/issues'
url='https://bottlepy.org/'
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('1c23aeb30aa8a13f39c60c0da494530ddd5de3da235bc431b818a50d999de49f')

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  # Undo path translation
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*.py; do
    sed -e '1 { s/^#!.*python.*$/#!\/usr\/bin\/env python3/ }' -i ${_f}
  done

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
